#open(BUFF,"file");
open(WRBUFF ,">tpedfile");
open(BUFF,"allchr_snvmix");
open(BUFF1,"mainids");
while($line = <BUFF1>)
{
	chomp($line);
	@array = split(" ",$line);
	$hash{"$array[0]_$array[3]"} = $array[1];
	#print "$array[0]_$array[3] ".$hash{"$array[0]_$array[3]"}."\n";
}
while($line = <BUFF>)
{
	chomp($line);
	#system("cat $line allchr_snvmix >> allchr_snvmix");
	@array = split(/\t/,$line);
	#print @array."\n";
	@array1 = split(":",$array[0]);
	$chr = $array1[0];
	$pos = $array1[1];
	$ref = $array[1];
	$alt = $array[2];
	@array2 = split(/\,/,$array[3]);
	$p1 = $array2[@array2-4];
	$p2 = $array2[@array2-3];		
	$p3 = $array2[@array2-2];
	$main = $array2[@array2-1];
	#print "$chr $pos $ref $alt $p1 $p2 $p3 $main\n";
	$chr =~ s/chr//g;
	$chr =~ s/X/23/g;
	$chr =~ s/Y/24/g;
	$chr =~ s/M/26/g;
	
	$m = "$chr"."_"."$pos";
	#print "$m $hash{"$m"}\n";
	if(exists($hash{"$m"}))
	{
		$id = $hash{"$m"};
	}
	else
	{
		$id = "tk37_".$chr."_$pos";

	}
	if($main == 1)
	{
		print WRBUFF "$chr $id 0 $pos $ref $ref $p1\n"; 
	}
	elsif($main == 3)
	{
		print WRBUFF "$chr $id 0 $pos $alt $alt $p3\n";
	}
	else
	{
		print WRBUFF "$chr $id 0 $pos $ref $alt $p2\n";
	} 
}
